448D - Multiplication Table - CodeForces Solution


binary search brute force *1800

Please click on ads to support us..

C++ Code:

// ============================================================================ //
// ||                                                                        || //
// ||             international university of business agriculture           || //
// ||                    and technology, dhaka, bangladesh                   || //
// ||                           emrul hasan emon                             || //
// ||                                                                        || //
// ============================================================================ //


///              b i s m i l l a h i r  r a h m a n i r  r a h i m


#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef bool                      boo;
typedef int                       li;
typedef long long int             ll;
typedef unsigned long long int    lu;
typedef double                    db;

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

typedef vector < li >                   vli;
typedef vector < ll >                   vll;
typedef set < li >                      sli;
typedef set < ll >                      sll;
typedef pair < pair<li, li>, li>        pli;
typedef pair < ll, ll >                 pll;
typedef map < li,li >                   mli;
typedef map < ll,ll >                   mll;
typedef vector < pair < li, li > >      vpi;
typedef vector < pair < ll, ll > >      vpl;

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#define tc                        int t;cin>>t;while(t--)
#define inp_i(a,n)                for(i=0; i<n ;i++) cin>>a[i]
#define out_i(a, b, c)            for(i=b; i<c; i++) cout<<a[i] spc; cout nl;
#define lp(i,a,b)                 for(i=a;i<b;i++)
#define len(z)                    z.begin(),z.end()
#define faster                    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define input_txt                 freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define nl                        <<"\n"
#define spc                       <<" "
#define sp                        <<" "<<
#define co(x)                     cout<<x nl
#define sz(a)                     a.size()
#define cy                        cout<<"yes" nl
#define cn                        cout<<"no" nl
#define pb                        push_back
#define f                         first
#define s                         second
#define pi                        2*acos(0.0)
#define clr(z)                    z.clear()
#define rn                        return
#define gcd(a,b)                  __gcd(a,b)
#define mem(b,z)                  memset(b,z,sizeof(b))
#define fixed(x)                  fixed<<setprecision(x)

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/*
template<typename t>
using ordered_set=tree<t,null_type,less<t>,rb_tree_tag,tree_order_statistics_node_update>;
*/

// Unordered Set
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;

// Unordered Set - Pair
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


const double inf = 0.0000;
const int lx = 1e5 + 23;
const ll mod = 1e9 + 7;


void solve()
{
    ll n, m, k;
    cin >> n >> m >> k;
    
    ll low = 1, high = n*m + 1, mid, ans = 0;
    
    
    while(low < high)
    {
	mid = (low+high)/2;
	ll cnt = 0;
	for(int i = 1; i <= n; i++)
	{
	    cnt += min((mid-1)/i, m);
	}
	if(cnt < k)
	{
	    low = mid+1;
	    ans = mid;
	}
	else
	{
	    high = mid;
	}
    }
    cout << ans << '\n';
}

void init_code()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

int main()
{
    faster
   
    solve();
// a l h a m d u l i l l a h
// 1 2 3 2 1
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/*
bool mark[lx];
vector<int> primes;

void sieve()
{
    mark[0] = mark[1] = true;
    
    for(int i = 3; i*i <= lx; i++)
    {
	if(!mark[i])
	{
	    for(int j = i*i; j < lx; j += i)
		mark[j] = true;
	}
    }
    
    primes.push_back(2);
    for(int i = 3; i < lx; i += 2)
    {
	if(!mark[i])
	{
	    primes.push_back(i);
	}
    }
}
* 
ll big_mod(ll a, ll b)
{
	if(!b) return 1;
	ll ans = big_mod(a, b/2);
	ans %= mod;
	ans *= ans;
	ans %= mod;
	
	if(b&1)
	{
		a %= mod;
		ans *= a;
		ans %= mod;
	}
	return ans;
}
* 
ll fact(ll n)
{
    ll ans=1;
    for(ll i=1; i<=n; i++)
        ans=(ans*i)%mod;
    return ans;
}

ll ncr(ll n, ll k)
{
    return fact(n)*1ll*big_mod(fact(k), mod-2)%mod*1ll*big_mod(fact(n-k), mod-2)%mod;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

void number_of_divisors(li n)
{
    //number of divisors of every number between 1 to n
    for(li i = 1; i*i <= n; i++)
    {
        for(li j = i*i; j <= n; j += i)
        {
            if(i*i == j)
                a[j]++;
            else
                a[j] += 2;
        }
    }
}

void sum_of_divisor()
{
    for(li i = 1; i * i <= 1e7; i++)
    {
        for(li j = i*i; j < 1e7; j += i)
        {
            if(j == i*i)
                a[j] += i;
            else
                a[j] += i+(j/i);
        }
    }
}

*/


Comments

Submit
0 Comments
More Questions

581B - Luxurious Houses
1481C - Fence Painting
935A - Fafa and his Company
22A - Second Order Statistics
1720B - Interesting Sum
1720A - Burenka Plays with Fractions
3A - Shortest path of the king
1720C - Corners
574A - Bear and Elections
352B - Jeff and Periods
1244A - Pens and Pencils
1670A - Prof Slim
1189A - Keanu Reeves
678A - Johny Likes Numbers
1699C - The Third Problem
1697D - Guess The String
754B - Ilya and tic-tac-toe game
760A - Petr and a calendar
1573A - Countdown
166A - Rank List
1631B - Fun with Even Subarrays
727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good